home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / createMayaHardwareCommonGlob < prev    next >
Encoding:
Text File  |  2003-07-17  |  74.5 KB  |  2,500 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // ----------------------------------------------------------------------------
  18. // Utility procedures used by other procedures in this file
  19. //
  20.  
  21. // Keep track of the height/width ratio.
  22. global float $deviceAspect = 0;
  23.  
  24. proc setParentToCommonTab()
  25. {
  26.     setParent `rendererTabLayoutName("mayaHardware")`;
  27.     setParent commonTabColumn;
  28. }
  29.  
  30. // ----------------------------------------------------------------------------
  31. // Code to create and update the file name preview area 
  32. //
  33.  
  34. proc createTargetFilePreview()
  35. {
  36.     string $oldParent = `setParent -query`;
  37.  
  38.     columnLayout 
  39.         -adjustableColumn true
  40.         mayaHardwareTargetFilePreview;
  41.  
  42.         text 
  43.             -align "left" 
  44.             -font "boldLabelFont" 
  45.             -label "Path" 
  46.             exampleText0;
  47.         text 
  48.             -align "left" 
  49.             -font "boldLabelFont" 
  50.             -label "File Name" 
  51.             exampleText1;
  52.         text 
  53.             -align "left" 
  54.             -font "boldLabelFont" 
  55.             -label "To" 
  56.             exampleText2;
  57.  
  58.     setParent $oldParent;
  59.  
  60.     // This target file preview is affected by a number of attributes.
  61.     // If any of those attributes change, this preview needs to be updated.
  62.     //
  63.     // Here we fill an array with the names of all of the current renderer's 
  64.     // attributes which affect the naming of the target file.
  65.     //
  66.     string $attrArray[];
  67.  
  68.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.filename";
  69.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.imageFormat";
  70.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.byFrame";
  71.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.startFrame";
  72.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.endFrame";
  73.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.modifyExtension";
  74.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.startExtension";
  75.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.byExtension";
  76.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.useCustomExtension";
  77.     $attrArray[size($attrArray)] = "hardwareRenderGlobals.customExtension";
  78.  
  79.     // Now we establish scriptJobs to invoke the procedure which updates the
  80.     // target file preview when any of the above attributes change.
  81.     //
  82.     int $i;
  83.  
  84.     for ($i = 0; $i < size($attrArray); $i++)
  85.     {
  86.         scriptJob
  87.             -attributeChange 
  88.                 $attrArray[$i]
  89.                 "updateMayaHardwareTargetFilePreview"
  90.             -parent mayaHardwareTargetFilePreview;
  91.     }
  92.  
  93.     scriptJob 
  94.         -parent mayaHardwareTargetFilePreview
  95.         -event 
  96.             workspaceChanged 
  97.             "updateMayaHardwareTargetFilePreview";
  98. }
  99.  
  100. global proc updateMayaHardwareTargetFilePreview()
  101. {
  102.     //
  103.     // Description:
  104.     //    This procedure is called any time an attribute change occurs which 
  105.     //     would affect the name(s) of the file(s) that would be created when the
  106.     //     user performs a render.
  107.     //    This procedure updates the lines of text in the General tab that allow
  108.     //    the user to see what files are going to be created when they render.
  109.     //
  110.  
  111.     string $oldParent = `setParent -query`;
  112.  
  113.     string $renderer = "mayaHardware";
  114.     string $tabLayout = rendererTabLayoutName($renderer);
  115.     setParent $tabLayout;
  116.  
  117.     //
  118.     // Update the Path portion of the preview.
  119.     //
  120.  
  121.     // get the project's image directory
  122.     //
  123.     string $imgDir = `workspace -q -rte "images"`;
  124.     string $fullPath = `workspace -expandName $imgDir`;
  125.  
  126.     $path = "  Path: "+ $fullPath + "/";
  127.  
  128.     text -edit -label $path exampleText0;
  129.  
  130.     //
  131.     // Update the File Name portion of the preview.
  132.     //
  133.  
  134.     string $title1 = "  File Name:  ";
  135.     string $title2 = "  To:             ";
  136.  
  137.     string $filename = `getAttr hardwareRenderGlobals.filename`;
  138.     string $prefix;
  139.  
  140.     // Image extension
  141.     string $imageType="";
  142.  
  143.     if (`getAttr "hardwareRenderGlobals.useCustomExtension"`)
  144.     {
  145.         // User specified
  146.         $imageType = "."+`getAttr "hardwareRenderGlobals.customExtension"` ;
  147.     }
  148.     else
  149.     {
  150.         global string $imgExt[];  // This is the actual file extension
  151.         global int $imgExtNum[];  // This is the corresponding internal value
  152.         int $imageNum = `getAttr "hardwareRenderGlobals.imageFormat"`;
  153.         int $i;
  154.         for ($i=0; $i < size($imgExtNum); ++$i) 
  155.         {
  156.             if ($imageNum == $imgExtNum[$i]) 
  157.             {
  158.                 $imageType = "."+$imgExt[$i];
  159.                 break;
  160.             }
  161.         }
  162.     }
  163.     // int $imageUse = 0;
  164.  
  165.     // Frames number extension
  166.     float $startFrame = `getAttr "hardwareRenderGlobals.startFrame"`;
  167.     float $endFrame = `getAttr "hardwareRenderGlobals.endFrame"`;
  168.  
  169. //    if ($useAnim) 
  170. //    {
  171. //        // if useAnim, make sure it's not a movie format, or else
  172. //        // bad extension names will be printed out to the window.
  173. //        int $imgFormat = `getAttr "hardwareRenderGlobals.imageFormat"`;
  174. //        if ($imgFormat == 21 || $imgFormat == 22 || $imgFormat == 23)
  175. //            $useAnim = 0;
  176. //    }
  177. //    if ($useAnim) 
  178. //    {
  179.         float $byf = `getAttr hardwareRenderGlobals.byFrame`;
  180.         if ($byf == 0.0) $byf = 0.00001;
  181.  
  182.         int $pad = `intFieldGrp -query -value1 framePaddingCtrl`;
  183.         
  184.         // Check if the padding is a valid number.  A valid
  185.         // padding is >= 0.
  186.         //
  187.         if ($pad < 0)
  188.         {
  189.             intFieldGrp -edit -value1 0 framePaddingCtrl;
  190.             $pad = 0;
  191.         }
  192.  
  193.         int $f1 = `getAttr "hardwareRenderGlobals.startFrame"`;
  194.         int $f2 = `getAttr "hardwareRenderGlobals.endFrame"`;
  195.         int $numFrames = ($f2 - $f1) / $byf;
  196.  
  197.         // Check to see if the numbers are being modified
  198.         if (`getAttr "hardwareRenderGlobals.modifyExtension"`) 
  199.         {
  200.             $f1 = `getAttr hardwareRenderGlobals.startExtension`;
  201.             $f2 = $f1 
  202.                 + ($numFrames * `getAttr hardwareRenderGlobals.byExtension`);
  203.         }
  204.  
  205.     // Check for fields
  206.  
  207. //    string $fieldExt = "";
  208. //    int $whichFields = `getAttr hardwareRenderGlobals.fields`;
  209. //    int $useFields = ($whichFields != 0);
  210. //    int $useFieldExt = (`getAttr "hardwareRenderGlobals.fieldExtControl"` != 1);
  211. //    int $defFieldExt = (`getAttr "hardwareRenderGlobals.fieldExtControl"` == 0);
  212.     
  213.     // Construct the file names 
  214.     //
  215.     int $useAnim = `getAttr "defaultRenderGlobals.animation"`; 
  216.     string $filename1; 
  217.  
  218.     // If we are using a animation format, then we don't need frame
  219.     // number in the file name.
  220.     //
  221.     if (checkMayaHardwareMultiframeFormat())
  222.     {
  223.         $useAnim = false;
  224.     }
  225.  
  226.     if ($useAnim)
  227.     {
  228.         $filename1 = `hwRender -imageFileName -frame $f1`;
  229.     }
  230.     else
  231.     {
  232.         $filename1 = `hwRender -imageFileName `;
  233.     }
  234.  
  235.  
  236.     // Set the example file text control.
  237.     //
  238.     text 
  239.         -edit 
  240.         -label ($title1+$filename1) 
  241.         exampleText1;
  242.  
  243.     if ($useAnim) 
  244.     {
  245.         string $filename2 = `hwRender -imageFileName  -frame $f2`;
  246.         text 
  247.             -edit 
  248.             -label ($title2+$filename2) 
  249.             exampleText2;
  250.     } 
  251.     else 
  252.     {
  253.         text -edit -label "" exampleText2;
  254.     }
  255.  
  256.     setParent $oldParent;
  257. }
  258.  
  259. // ----------------------------------------------------------------------------
  260. // Code to create and update the Image File Output frame 
  261. //
  262.  
  263. proc createFileNamePrefixControl()
  264. {
  265.     // Create the control
  266.     //
  267.     textFieldGrp 
  268.         -label "File Name Prefix" 
  269.         -changeCommand ("changeMayaHardwareFileNamePrefix")
  270.         mayaHardwareFilePrefix;
  271.  
  272.     // Create a scriptJob which will update the control when the value of the
  273.     // attribute it represents is changed.
  274.     //
  275.     scriptJob
  276.         -parent mayaHardwareFilePrefix
  277.         -attributeChange 
  278.             "hardwareRenderGlobals.filename"
  279.             "updateMayaHardwareFilenameRelatedControls";
  280.  
  281.     scriptJob
  282.         -parent mayaHardwareFilePrefix
  283.         -attributeChange 
  284.             "defaultRenderGlobals.animation"
  285.             "updateMayaHardwareFilenameRelatedControls";
  286. }
  287.  
  288. // Description:  This procedure is called when we want to refresh the content
  289. //      in the file name prefix control.
  290. //
  291. proc updateMayaHardwareFileNamePrefixControl(string $prefix)
  292. {
  293.     string $oldParent = `setParent -q`;
  294.     setParentToCommonTab();
  295.  
  296.     if ($prefix == "%s")
  297.     {
  298.         $prefix = "(not set; using filename)"; 
  299.     } 
  300.  
  301.     // Update the "File Name Prefix"  and the "File/Animation Ext" controls.
  302.     //
  303.     textFieldGrp -edit -text $prefix mayaHardwareFilePrefix;
  304.  
  305.     setParent $oldParent;
  306. }
  307.  
  308. // Description:  This procedure is called to extract the frame padding
  309. //      string from the filename.
  310. //
  311. //      The way HWRenderMaya\Render\TimageName.cpp works is that it takes
  312. //      the last frame number specification as
  313. //      the "official" frame number pattern.
  314. //
  315. //      Example 1:
  316. //          filename = "myFile%5n_separator_%3n_ending"
  317. //      will give filenames like
  318. //          myFile%5n_separator_001_ending
  319. //          myFile%5n_separator_002_ending
  320. //
  321. //      Example 2:
  322. //          filename = "myFile%3n_separator_%3n_ending"
  323. //      will give filenames like
  324. //          myFile001_separator_001_ending
  325. //          myFile001_separator_002_ending
  326. //
  327. proc string extractFramePaddingString(string $filename)
  328. {
  329.     int $lengthFilename = size($filename);
  330.  
  331.     // If there is no frame number pattern, then we return the empty string.
  332.     //
  333.     if (`match "%[-._][0-9]*n" $filename` == "" &&
  334.         `match "%[0-9]*n" $filename` == "" )
  335.     {
  336.           return "";
  337.     }
  338.  
  339.     // Check substring ending to find the last frame number pattern.
  340.     //
  341.     int $lengthSubstring = $lengthFilename;
  342.     while ($lengthSubstring >= 2 && $lengthSubstring <= $lengthFilename)
  343.     {
  344.         // Check the substring filename[1..i].
  345.         // If the end of this substring is a frame number specification,
  346.         // then extract the frame padding from it.
  347.         //
  348.         string $myString = `substring $filename 1 $lengthSubstring`;
  349.         string $paddingString = `match "%[-._][0-9]*n$" $myString`;
  350.         if ($paddingString != "")
  351.         {
  352.             return $paddingString;
  353.         }
  354.  
  355.         $paddingString = `match "%[0-9]*n$" $myString`;
  356.         if ($paddingString != "")
  357.         {
  358.             return $paddingString;
  359.         }
  360.  
  361.         // If we don't have a frame number pattern at the end of the
  362.         // substring, we chop a character from the end of the substring
  363.         // and search again.
  364.         //
  365.         $lengthSubstring = $lengthSubstring -1;
  366.     }
  367. }
  368.  
  369. // Description:  This procedure is called to extract the frame padding
  370. //      number out of the given filename.
  371. //
  372. proc int extractFramePadding(string $filename)
  373. {
  374.     string $paddingString = extractFramePaddingString($filename);
  375.  
  376.     // If there is no frame padding pattern in the filename, we return -1.
  377.     //
  378.     if ($paddingString == "")
  379.     {
  380.         return -1;
  381.     }
  382.  
  383.     $paddingString = `match "[0-9]*n$" $paddingString`;
  384.     $paddingString = `match "[0-9]*" $paddingString`;
  385.     int $padding;
  386.     if ($paddingString == "")
  387.     {
  388.         // It must be the cases %n or %[-._]n, where frame padding is 1.
  389.         //
  390.         $padding = 1;
  391.     }
  392.     else
  393.     {
  394.         $padding = $paddingString;
  395.     }
  396.  
  397.     if ($padding == 0)
  398.     {
  399.         $padding = 1;
  400.     }
  401.     return $padding;
  402. }
  403.  
  404. // Description:  This procedure is called when the image format is changed
  405. //      to an animation format.  We need to 
  406. //          . extact the filen prefix,
  407. //          . update the Frame/Animation Ext accordingly,
  408. //          . disable controls which are not useful for the animation format. 
  409. //      
  410. proc updateMayaHardwareMultiFrameControls()
  411. {
  412.     string $oldParent = `setParent -q`;
  413.     setParentToCommonTab();
  414.  
  415.     // Fix filename pattern to make sure the output filenames are unique.
  416.     // In this procedure we deal with the case where the image format
  417.     // is an animation format.  After fixFileNameNumberPattern,
  418.     // the new version of the $hwFileName has its frame number
  419.     // pattern removed.
  420.     //
  421.     string $hwFilename = `hwRender -query -fixFileNameNumberPattern`;
  422.  
  423.     int $anim = `getAttr defaultRenderGlobals.animation`;
  424.     int $item = 1;
  425.     string $ending = "";
  426.  
  427.     // Extract the .ext ending of a filename if there is any.
  428.     //
  429.     if (`match "[.]%e$" $hwFilename` != "")
  430.     {
  431.         $ending = "[.]%e$";
  432.     } 
  433.     else if (`match "%[.]e$" $hwFilename` != "")
  434.     {
  435.         $ending = "%[.]e$";
  436.     }
  437.  
  438.     // Extract the prefix.
  439.     //
  440.     string $prefix = `substitute $ending $hwFilename ""`; 
  441.     updateMayaHardwareFileNamePrefixControl($prefix);
  442.  
  443.  
  444.     // Set the "Frame/Animation Ext" to the appropriate menuItem.
  445.     //
  446.     if ($ending != "")
  447.     {
  448.         // There is an extension.
  449.         //
  450.         if ($anim)
  451.         {
  452.             // name.ext (Multi Frame)
  453.             //
  454.             $item = 8; 
  455.         }
  456.         else
  457.         {
  458.             // name.ext (Single Frame)
  459.             //
  460.             $item = 2; 
  461.         }
  462.     }
  463.     else
  464.     {
  465.         // No extension.
  466.         //
  467.         if ($anim)
  468.         {
  469.             // name (Multi Frame)
  470.             //
  471.             $item = 7;
  472.         }
  473.         else
  474.         {
  475.             // name (Single Frame)
  476.             //
  477.             $item = 1;
  478.         }
  479.     }
  480.     optionMenuGrp -edit -select $item mayaHardwareExtMenu;
  481.  
  482.     setParent $oldParent;
  483. }
  484.  
  485. // Description:  This procedure is called when a image file format is used
  486. //      and we want to choose the appropriate Frame/Animation Ext and 
  487. //      set image filename related controls accordingly.
  488. // 
  489. proc updateMayaHardwareNonMultiFrameControls()
  490. {
  491.     string $oldParent = `setParent -q`;
  492.     setParentToCommonTab();
  493.  
  494.     // If the format is a non-animation format, update related controls.
  495.     //
  496.     string $originalHwFilename = `getAttr "hardwareRenderGlobals.filename"`;
  497.     int $animation =  mayaHardwareGetCommonGlobalValue("animation"); 
  498.     int $padding;
  499.  
  500.     // If we are in animation mode and the filename does not have a
  501.     // frame number specification, then add a frame number specification
  502.     // to the end of the filename.
  503.     //
  504.     if ($animation)
  505.     {
  506.         string $paddingString = 
  507.             extractFramePaddingString($originalHwFilename);
  508.         if ($paddingString == "")
  509.         {
  510.             // There is no frame number specification, so we add the 
  511.             // frame number specification at the end of the filename.
  512.             //
  513.             $padding = `intFieldGrp -query -value1 framePaddingCtrl`;
  514.             if ($padding <= 1)
  515.             {
  516.                 $paddingString = ".%n";
  517.             }
  518.             else
  519.             {
  520.                 $paddingString = ".%"+$padding+"n";
  521.             }
  522.  
  523.             // Put the frame number specification string at the 
  524.             // end of the filename.
  525.             //
  526.             $originalHwFilename = $originalHwFilename + $paddingString;
  527.             setAttr hardwareRenderGlobals.filename -type "string"
  528.                 $originalHwFilename;
  529.  
  530.             // There is a scriptJob which calls this function when
  531.             // the filename attribute is changed.  The setAttr
  532.             // code above will trigger this scriptJob again.  
  533.             // we do not want to run the code below twice, 
  534.             // so we return.
  535.             // 
  536.             return;
  537.         }
  538.     }
  539.     
  540.     // Fix filename pattern to make sure the output filenames are unique.
  541.     //
  542.     string $hwFilename = `hwRender -query -fixFileNameNumberPattern`;
  543.  
  544.     string $patternArray[];
  545.     int $itemArray[];
  546.  
  547.     $i = 0; 
  548.  
  549.     // Possible pattern: name.#.ext
  550.     //
  551.     $patternArray[$i] = "[.]%[0-9]*n[.]%e$"; $itemArray[$i] = 3; $i=$i+1;
  552.     $patternArray[$i] = "%[.][0-9]*n[.]%e$"; $itemArray[$i] = 3; $i=$i+1;
  553.     $patternArray[$i] = "%[.][0-9]*n%[.]e$"; $itemArray[$i] = 3; $i=$i+1;
  554.     $patternArray[$i] = "[.]%[0-9]*n%[.]e$"; $itemArray[$i] = 3; $i=$i+1;
  555.  
  556.     // Possible pattern: name#.ext
  557.     //
  558.     $patternArray[$i] = "%[0-9]*n%[.]e$"; $itemArray[$i] = 6; $i=$i+1;
  559.     $patternArray[$i] = "%[0-9]*n[.]%e$"; $itemArray[$i] = 6; $i=$i+1;
  560.  
  561.     // Possible pattern: name.ext
  562.     //
  563.     $patternArray[$i] = "[.]%e$"; $itemArray[$i] = 2; $i=$i+1;
  564.     $patternArray[$i] = "%[.]e$"; $itemArray[$i] = 2; $i=$i+1;
  565.  
  566.     // Possible pattern: name.ext.#
  567.     //
  568.     $patternArray[$i] = "[.]%e[.]%[0-9]*n$"; $itemArray[$i] = 4; $i=$i+1;
  569.     $patternArray[$i] = "[.]%e%[.][0-9]*n$"; $itemArray[$i] = 4; $i=$i+1;
  570.     $patternArray[$i] = "%[.]e%[.][0-9]*n$"; $itemArray[$i] = 4; $i=$i+1;
  571.     $patternArray[$i] = "%[.]e[.]%[0-9]*n$"; $itemArray[$i] = 4; $i=$i+1;
  572.  
  573.     // Possible pattern: name.#
  574.     //
  575.     $patternArray[$i] = "[.]%[0-9]*n$"; $itemArray[$i] = 5; $i=$i+1;
  576.     $patternArray[$i] = "%[.][0-9]*n$"; $itemArray[$i] = 5; $i=$i+1;
  577.  
  578.  
  579.  
  580.     // Look for an ending pattern the hwFilename matches with.
  581.     // Initially assume the filename is "custom", until we find a potential
  582.     // matching pattern for the filename ending. 
  583.     // 
  584.     int $item = 9;  
  585.     string $ending = "";
  586.     for ($i = 0; $i < size($patternArray); $i++)
  587.     {
  588.         
  589.         $ending = `match $patternArray[$i] $hwFilename`;
  590.         if ($ending != "")
  591.         {
  592.             $item = $itemArray[$i];
  593.             break;
  594.         }
  595.     }
  596.  
  597.     // If we have not found an ending pattern for the hwFilename yet,
  598.     // the hwFilename might be "name (Single Frame)" or "custom" 
  599.     //
  600.     if ($item == 9)
  601.     {
  602.         // Possible pattern: name with no frame number 
  603.         //
  604.         if (`match "%[0-9]*n" $hwFilename` == "" && 
  605.             `match "%[-._][0-9]*n" $hwFilename` == "") 
  606.         {
  607.             $ending = ""; 
  608.             $item = 1;
  609.         }
  610.     }
  611.  
  612.     string $prefix; 
  613.  
  614.     // When the ending of the file matches a "Frame/Animtion Ext"
  615.     // ending, check if the prefix is just a name or it is part
  616.     // of a custom filename.
  617.     // 
  618.     if ($item != 9)
  619.     {
  620.         // Temporarily set the "Frame/Animation Ext" to the item number.
  621.         //
  622.         optionMenuGrp -edit -select $item mayaHardwareExtMenu;
  623.  
  624.         // If it is animation setting, check if the prefix also contains
  625.         // the same frame number pattern as the ending.
  626.         //
  627.         if ( $animation ) 
  628.         {
  629.             // Extract the frame padding string from the original filename. 
  630.             // 
  631.             string $paddingString = 
  632.                 extractFramePaddingString($hwFilename);
  633.  
  634.             // If there is more than one occurrence of this frame number
  635.             // pattern, then it is a custom "Frame/Animation Ext".
  636.             //
  637.             if (`substitute $paddingString $hwFilename ""` !=
  638.                 `substituteAll $paddingString $hwFilename ""`)
  639.             {
  640.                 $item = 9;
  641.             } 
  642.         }
  643.         // If it is not an animation setting, check if the prefix 
  644.         // contains any frame number pattern.  If it does, it is 
  645.         // a custom "Frame/Animation Ext". 
  646.         //
  647.         else
  648.         {
  649.             $prefix = `substitute $ending $hwFilename ""`; 
  650.         
  651.             // Extract the frame padding string from the prefix. 
  652.             // 
  653.             string $paddingString = 
  654.                 extractFramePaddingString($prefix);
  655.  
  656.             if ($paddingString != "")
  657.             {
  658.                 $item = 9;
  659.             }
  660.         }
  661.     }
  662.  
  663.     // Separate the prefix from the ending.
  664.     //
  665.  
  666.     if ($item == 9)
  667.     {
  668.         // For custom filename, the prefix is the original filename.
  669.         //
  670.         $prefix = $originalHwFilename;
  671.         menuItem -edit -enable true mayaHardwareCustomFrameExtItem;    
  672.     }
  673.     else
  674.     {
  675.         $prefix = `substitute $ending $hwFilename ""`; 
  676.     }
  677.  
  678.     // Match the behavior of "File Name Prefix" control to that in
  679.     // software common tab.
  680.     //
  681.     if ($prefix == "")
  682.     {
  683.         $prefix = "%s";
  684.         $hwFilename = $prefix + $ending;
  685.         setAttr -type "string" hardwareRenderGlobals.filename $hwFilename;
  686.         return;
  687.     }
  688.  
  689.     updateMayaHardwareFileNamePrefixControl($prefix);
  690.  
  691.     // Update the "File/Animation Ext" controls.
  692.     //
  693.     optionMenuGrp -edit -select $item mayaHardwareExtMenu;
  694.  
  695.  
  696.     // Extract the frame padding from the filename. 
  697.     // 
  698.     $padding = extractFramePadding($hwFilename);
  699.     
  700.     // When there is no padding specified, we leave the current 
  701.     // frame padding number as it is.
  702.     // When there is a padding number specified, we update the 
  703.     // framePaddingCtrl.
  704.     // 
  705.     if ($padding > 0)
  706.     {
  707.         intFieldGrp -edit -value1 $padding framePaddingCtrl;
  708.     }
  709.  
  710.     setParent $oldParent;
  711. }
  712.  
  713. // Description:  This procedure is called when the image format is changed
  714. //      to 
  715. //          . either an animation format (multiframe == true),
  716. //          . or a non-animation format  (multiframe == false).  
  717. //      We need to update the Frame/Animation Ext accordingly.
  718. //      
  719. proc refreshMayaHardwareFrameAnimationExt(int $multiframe)
  720. {
  721.     // Enable/Disable Frame/Animtaion extension.
  722.     //
  723.     menuItem 
  724.         -edit -enable (!$multiframe)    
  725.         mayaHardwareNameDotFrameDotExtension;            
  726.     menuItem 
  727.         -edit -enable (!$multiframe)    
  728.         mayaHardwareNameDotExtensionDotFrame;
  729.     menuItem 
  730.         -edit -enable (!$multiframe)    
  731.         mayaHardwareNameDotFrame;
  732.     menuItem 
  733.         -edit -enable (!$multiframe)    
  734.         mayaHardwareNameFrameDotExtension;
  735.     menuItem 
  736.         -edit -enable $multiframe
  737.         mayaHardwareNameMultiFrame;
  738.     menuItem 
  739.         -edit -enable $multiframe
  740.         mayaHardwareNameDotExtensionMultiFrame;
  741.     menuItem 
  742.         -edit -enable false 
  743.         -label "custom" mayaHardwareCustomFrameExtItem;    
  744. }
  745.  
  746. // Description:  This procedure is called when the 
  747. //      hardwareRenderglobals.filename attribute is changed.
  748. //
  749. global proc updateMayaHardwareFilenameRelatedControls()
  750. {
  751.     string $oldParent = `setParent -q`;
  752.     setParentToCommonTab();
  753.  
  754.     // Depending on the new imageFormat is an animation format or a 
  755.     // non-animation format, we need to refresh Frame/Animation Ext control.
  756.     // 
  757.     int $multiframe = checkMayaHardwareMultiframeFormat(); 
  758.  
  759.     refreshMayaHardwareFrameAnimationExt($multiframe);
  760.  
  761.     // If the filename is empty, replace it by the default filename. 
  762.     //
  763.     string $originalHwFilename = `getAttr "hardwareRenderGlobals.filename"`;
  764.     if ($originalHwFilename == "")
  765.     {
  766.         $originalHwFilename = "%s.%e";
  767.         setAttr -type "string" hardwareRenderGlobals.filename 
  768.             $originalHwFilename; 
  769.  
  770.         // There is a scriptJob which calls this function when
  771.         // the filename attribute is changed.  The setAttr
  772.         // code above will trigger this scriptJob again.  
  773.         // we do not want to run the code below twice, 
  774.         // so we return.
  775.         // 
  776.         return;
  777.     }
  778.  
  779.     // If the format is a multiframe animation format, update related controls.
  780.     //
  781.     if ( $multiframe )
  782.     {
  783.         updateMayaHardwareMultiFrameControls();    
  784.     }
  785.     else
  786.     {
  787.         updateMayaHardwareNonMultiFrameControls();
  788.     }
  789.  
  790.     // Update the animation related controls and the use custom file
  791.     // extension controls.
  792.     //
  793.     updateMayaHardwareFrameNumberControls();
  794.     updateMayaHardwareCustomExtension();
  795.  
  796.     setParent $oldParent;
  797. }
  798.  
  799. // Description:  This procedure is called when the user changes the 
  800. //          file name prefix field from the unified render globals window.
  801. //
  802. global proc changeMayaHardwareFileNamePrefix()
  803. {
  804.     string $oldParent = `setParent -q`;
  805.     setParentToCommonTab();
  806.  
  807.     string $prefix = `textFieldGrp -query -text mayaHardwareFilePrefix`;
  808.  
  809.     // If the prefix is an empty string, 
  810.     // then let the prefix be "default-%s" where "%s" indicates
  811.     // that the scene name should be substituted in here.
  812.     //
  813.     if ($prefix == "")
  814.     {
  815.         $prefix = "%s"; 
  816.         textFieldGrp -edit -text $prefix mayaHardwareFilePrefix;
  817.     }
  818.  
  819.     // Update the filename change due to the change in prefix.
  820.     //
  821.     mayaHardwareFilenameChange();
  822.  
  823.     setParent $oldParent;
  824. }
  825.  
  826. proc createFileNameFormatControl()
  827. {
  828.     // The Maya Hardware Renderer currently supports only one output filename
  829.     // format. Although we will create a control which shows the same variety
  830.     // of output filename formats other renderers provide, the user will only
  831.     // be able to choose one of the available options.
  832.     //
  833.     optionMenuGrp 
  834.         -label "Frame/Animation Ext" 
  835.         -changeCommand ("mayaHardwareFilenameChange")
  836.         mayaHardwareExtMenu;
  837.  
  838.         menuItem 
  839.             -label "name (Single Frame)";            
  840.         menuItem 
  841.             -label "name.ext (Single Frame)";        
  842.         menuItem 
  843.             -label "name.#.ext"
  844.             mayaHardwareNameDotFrameDotExtension;            
  845.         menuItem 
  846.             -label "name.ext.#"    
  847.             mayaHardwareNameDotExtensionDotFrame;
  848.         menuItem 
  849.             -label "name.#"    
  850.             mayaHardwareNameDotFrame;
  851.         menuItem 
  852.             -label "name#.ext"    
  853.             mayaHardwareNameFrameDotExtension;
  854.         menuItem 
  855.             -label "name (Multi Frame)"    
  856.             mayaHardwareNameMultiFrame;
  857.         menuItem 
  858.             -label "name.ext (Multi Frame)"
  859.             mayaHardwareNameDotExtensionMultiFrame;
  860.         menuItem 
  861.             -label "custom" mayaHardwareCustomFrameExtItem;    
  862.         
  863.         // The user is not allowed to choose the item "custom" directly
  864.         // from the "Frame/Animation Ext" control, because it does
  865.         // specify how the filename should be formed differently from
  866.         // the six choices above.
  867.         //
  868.         menuItem -edit -enable false mayaHardwareCustomFrameExtItem;    
  869.  
  870. }
  871.  
  872. // Description: This procedure is called to change the frame padding
  873. //  information in the filename.
  874. //
  875. proc string changeFramePaddingInfoInFilename(string $filename, int $newPadding)
  876. {
  877.     string $paddingString = extractFramePaddingString($filename);
  878.     string $oldPaddingNumberString = `match "[0-9]*n" $paddingString`; 
  879.     string $newPaddingNumberString = $newPadding + "n";
  880.     string $newPaddingString = 
  881.         `substitute $oldPaddingNumberString $paddingString $newPaddingNumberString`;
  882.     string $newFilename = 
  883.         `substituteAll $paddingString $filename $newPaddingString`;
  884.     return $newFilename;
  885. }
  886.  
  887. global proc mayaHardwareFilenameChange()
  888. //
  889. //  Procedure Name:
  890. //      mayaHardwareFilenameChange
  891. //
  892. //  Description:
  893. //        This procedure is called when the user changes the format
  894. //        of the file extension.  It sets the internal representation 
  895. //        and then updates the example to show the changes.
  896. //
  897. //    Note:
  898. //        Although the user sees only one control to change the
  899. //        extension, it actually affects more than one value.
  900. //
  901. {
  902.     string $oldParent = `setParent -q`;
  903.     setParentToCommonTab();
  904.  
  905.     global string $imgExt[];  // This is the actual file extension
  906.     global int $imgExtNum[];  // This is the corresponding internal value
  907.  
  908.     int $item = `optionMenuGrp -q -sl mayaHardwareExtMenu`;
  909.  
  910.     // Specify the filename pattern.
  911.     // 
  912.     string $hwFilename = "";
  913.  
  914.     switch ($item)
  915.     {
  916.         case 1: 
  917.             $hwFilename = "name";
  918.             break;
  919.         case 2:
  920.             $hwFilename = "name.%e";
  921.             break;
  922.         case 3:
  923.             $hwFilename = "name.%n.%e";
  924.             break;
  925.         case 4:
  926.             $hwFilename = "name.%e.%n";
  927.             break;
  928.         case 5:
  929.             $hwFilename = "name.%n";
  930.             break;
  931.         case 6:
  932.             $hwFilename = "name%n.%e";
  933.             break;
  934.         case 7: 
  935.             $hwFilename = "name";
  936.             break;
  937.         case 8:
  938.             $hwFilename = "name.%e";
  939.             break;
  940.         case 9:
  941.             $hwFilename = "name";
  942.             break;
  943.     }
  944.  
  945.     // When the setting is not custom, set the animation attribute.
  946.     //
  947.     int $animation = true;
  948.     if ($item == 1 || $item == 2)
  949.     {
  950.         $animation = false;
  951.     }   
  952.     setAttr defaultRenderGlobals.animation $animation;
  953.     
  954.     if ($item != 9)
  955.     {
  956.         // The new choice is not "custom", so we disable the selection
  957.         // "custom".
  958.         //
  959.         menuItem -edit -enable false mayaHardwareCustomFrameExtItem;    
  960.     }
  961.  
  962.     // Only substitute the image frame number for cases where the
  963.     // padding number should be controlled by the "Frame Padding"
  964.     // control.
  965.     //
  966.     if ($item >=3 && $item <= 6)
  967.     {
  968.         // Substitute in the user specified frame padding.
  969.         //
  970.         int $pad = `intFieldGrp -query -value1 framePaddingCtrl`;
  971.     
  972.         if ($pad > 1)
  973.         {
  974.             string $frameNumberString = "%"+$pad+"n";
  975.             $hwFilename = `substitute "%n" $hwFilename $frameNumberString`;
  976.         }
  977.     }
  978.  
  979.     // Substitute in the user specified prefix.
  980.     //
  981.     string $prefix = `textFieldGrp -query -text mayaHardwareFilePrefix`;
  982.     if ($prefix == "(not set; using filename)")
  983.     {
  984.         $prefix = "%s";
  985.     }
  986.     $hwFilename = `substitute "name" $hwFilename $prefix`;
  987.  
  988.     setAttr -type "string" "hardwareRenderGlobals.filename" $hwFilename;
  989.     updateMayaHardwareFilenameRelatedControls;
  990.  
  991.     setParent $oldParent;
  992. }
  993.  
  994. proc createHwCompressorControlForMac(int $item)
  995. {
  996.         global string $imgExt[];
  997.         rowLayout -adjustableColumn true -nc 4 ;
  998.         text -l "";
  999.         button -l "Compression..." -width 80 -enable false -c "movieCompressor -hardwareOptions" renderHwGlobalsCompression;
  1000.         text -l "";
  1001.         text -l "";
  1002.         setParent ..;
  1003.         if($imgExt[$item] == "qt"){
  1004.             button -e -enable true renderHwGlobalsCompression;
  1005.         }
  1006.     
  1007. }
  1008.  
  1009. proc enableHwMacCompressorbutton(int $item)
  1010. {
  1011.     global int  $imgExtNum[];
  1012.     if(`about -mac`){
  1013.         if($imgExtNum[$item] == 22){
  1014.             button -e -enable true renderHwGlobalsCompression;
  1015.         }else{
  1016.             button -e -enable false renderHwGlobalsCompression;
  1017.         }
  1018.     }
  1019. }
  1020.  
  1021. proc createImageFormatControl()
  1022. {
  1023.     string $parent = `setParent -query`;
  1024.  
  1025.    optionMenuGrp 
  1026.         -label "Image Format" 
  1027.         -changeCommand "changeMayaHardwareImageFormat"
  1028.         hardwareImageMenu;
  1029.         
  1030.     if (`about -nt`) 
  1031.     {
  1032.         menuItem -label "Alias PIX (als)";      //  $imgExt[0]  = "als";  $imgExtNum[0]  = 6;
  1033.         menuItem -label "AVI (avi)";            //  $imgExt[1]  = "avi";  $imgExtNum[1]  = 23;
  1034.         menuItem -label "Cineon (cin)";         //  $imgExt[2]  = "cin";  $imgExtNum[2]  = 11;
  1035.         menuItem -label "EPS (eps)";            //  $imgExt[3]  = "eps";  $imgExtNum[3]  = 9;
  1036.         menuItem -label "GIF (gif)";            //  $imgExt[4]  = "gif";  $imgExtNum[4]  = 0;
  1037.         menuItem -label "JPEG (jpeg)";          //  $imgExt[5]  = "jpeg"; $imgExtNum[5]  = 8;
  1038.         menuItem -label "Maya IFF (iff)";       //  $imgExt[6]  = "iff";  $imgExtNum[6]  = 7;
  1039.         menuItem -label "Maya16 IFF (iff)";     //  $imgExt[7]  = "iff";  $imgExtNum[7]  = 10;
  1040.         menuItem -label "Quantel (yuv)";        //  $imgExt[8]  = "yuv";  $imgExtNum[8]  = 12;
  1041.         menuItem -label "RLA (rla)";            //  $imgExt[9]  = "rla";  $imgExtNum[9]  = 2;
  1042.         menuItem -label "SGI (sgi)";            //  $imgExt[10] = "sgi";  $imgExtNum[10]  = 5;
  1043.         menuItem -label "SGI16 (sgi)";          //  $imgExt[11] = "sgi";  $imgExtNum[11] = 13;
  1044.         menuItem -label "SoftImage (pic)";      //  $imgExt[12] = "pic";  $imgExtNum[12] = 1;
  1045.         menuItem -label "Targa (tga)";          //  $imgExt[13] = "tga";  $imgExtNum[13] = 19;
  1046.         menuItem -label "Tiff (tif)";           //  $imgExt[14] = "tif";  $imgExtNum[14] = 3;
  1047.         menuItem -label "Tiff16 (tif)";         //  $imgExt[15] = "tif";  $imgExtNum[15] = 4;
  1048.         menuItem -label "Windows Bitmap (bmp)"; //  $imgExt[16] = "bmp";  $imgExtNum[16] = 20;
  1049.     } 
  1050.     else if (`about -irix`)  
  1051.     {
  1052.         menuItem -label "Alias PIX (als)";        //  $imgExt[0]  = "als";  $imgExtNum[0]  = 6;
  1053.         menuItem -label "AVI (avi)";            //  $imgExt[1]  = "avi";  $imgExtNum[1]  = 23;
  1054.         menuItem -label "Cineon (cin)";            //  $imgExt[2]  = "cin";  $imgExtNum[2]  = 11;
  1055.         menuItem -label "EPS (eps)";            //  $imgExt[3]  = "eps";  $imgExtNum[3]  = 9;
  1056.         menuItem -label "GIF (gif)";            //  $imgExt[4]  = "gif";  $imgExtNum[4]  = 0;
  1057.         menuItem -label "JPEG (jpeg)";            //  $imgExt[5]  = "jpeg"; $imgExtNum[5]  = 8;
  1058.         menuItem -label "Maya IFF (iff)";          //  $imgExt[6]  = "iff";  $imgExtNum[6]  = 7;
  1059.         menuItem -label "Maya16 IFF (iff)";        //  $imgExt[7]  = "iff";  $imgExtNum[7]  = 10;
  1060.         menuItem -label "Quantel (yuv)";        //  $imgExt[8]  = "yuv";  $imgExtNum[8]  = 12;
  1061.         menuItem -label "Quicktime (qt)";        //  $imgExt[9]  = "qt";   $imgExtNum[9]  = 22;
  1062.         menuItem -label "RLA (rla)";            //  $imgExt[10]  = "rla"; $imgExtNum[10]  = 2;
  1063.         menuItem -label "SGI (sgi)";            //  $imgExt[11] = "sgi";  $imgExtNum[11]  = 5;
  1064.         menuItem -label "SGI16 (sgi)";            //  $imgExt[12] = "sgi";  $imgExtNum[12] = 13;
  1065.         menuItem -label "SGI Movie (mv)";        //  $imgExt[13] = "mv";   $imgExtNum[13] = 21;
  1066.         menuItem -label "SoftImage (pic)";        //  $imgExt[14] = "pic";  $imgExtNum[14] = 1;
  1067.         menuItem -label "Targa (tga)";            //  $imgExt[15] = "tga";  $imgExtNum[15] = 19;
  1068.         menuItem -label "Tiff (tif)";            //  $imgExt[16] = "tif";  $imgExtNum[16] = 3;
  1069.         menuItem -label "Tiff16 (tif)";            //  $imgExt[17] = "tif";  $imgExtNum[17] = 4;
  1070.         menuItem -label "Windows Bitmap (bmp)";    //  $imgExt[18] = "bmp";  $imgExtNum[18] = 20; 
  1071.     } 
  1072.     else if (`about -linux`)  
  1073.     {
  1074.         menuItem -label "Alias PIX (als)";        //  $imgExt[0]  = "als";  $imgExtNum[0]  = 6;
  1075.         menuItem -label "Cineon (cin)";            //  $imgExt[1]  = "cin";  $imgExtNum[1]  = 11;
  1076.         menuItem -label "EPS (eps)";            //  $imgExt[2]  = "eps";  $imgExtNum[2]  = 9;
  1077.         menuItem -label "GIF (gif)";            //  $imgExt[3]  = "gif";  $imgExtNum[3]  = 0;
  1078.         menuItem -label "JPEG (jpeg)";            //  $imgExt[4]  = "jpeg"; $imgExtNum[4]  = 8;
  1079.         menuItem -label "Maya IFF (iff)";          //  $imgExt[5]  = "iff";  $imgExtNum[5]  = 7;
  1080.         menuItem -label "Maya16 IFF (iff)";        //  $imgExt[6]  = "iff";  $imgExtNum[6]  = 10;
  1081.         menuItem -label "Quantel (yuv)";        //  $imgExt[7]  = "yuv";  $imgExtNum[7]  = 12;
  1082.         menuItem -label "RLA (rla)";            //  $imgExt[8]  = "rla";  $imgExtNum[8]  = 2;
  1083.         menuItem -label "SGI (sgi)";            //  $imgExt[9] = "sgi";   $imgExtNum[9]  = 5;
  1084.         menuItem -label "SGI16 (sgi)";            //  $imgExt[10] = "sgi";  $imgExtNum[10] = 13;
  1085.         menuItem -label "SoftImage (pic)";        //  $imgExt[11] = "pic";  $imgExtNum[11] = 1;
  1086.         menuItem -label "Targa (tga)";            //  $imgExt[12] = "tga";  $imgExtNum[12] = 19;
  1087.         menuItem -label "Tiff (tif)";            //  $imgExt[13] = "tif";  $imgExtNum[13] = 3;
  1088.         menuItem -label "Tiff16 (tif)";            //  $imgExt[14] = "tif";  $imgExtNum[14] = 4;
  1089.         menuItem -label "Windows Bitmap (bmp)";    //  $imgExt[15] = "bmp";  $imgExtNum[15] = 20; 
  1090.     } 
  1091.     else if (`about -mac`) 
  1092.     {
  1093.         menuItem -label "JPEG (jpeg)";            //    $imgExt[0]  = "jpeg"; $imgExtNum[0]  = 8;
  1094.         menuItem -label "Maya IFF (iff)";          //    $imgExt[1]  = "iff";  $imgExtNum[1]  = 7;
  1095.         menuItem -label "Maya16 IFF (iff)";        //    $imgExt[2]  = "iff";  $imgExtNum[2]  = 10;
  1096.         menuItem -label "MacPaint (pntg)";          //    $imgExt[3]  = "pntg"; $imgExtNum[3]  = 30;
  1097.         menuItem -label "Photoshop (ps)";        //    $imgExt[4]  = "ps";      $imgExtNum[4]  = 31;
  1098.         menuItem -label "PNG (png)";               //    $imgExt[5]  = "png";  $imgExtNum[5]  = 32;
  1099.         menuItem -label "QuickDraw (pict)";        //    $imgExt[6]  = "pict"; $imgExtNum[6]  = 33;
  1100.         menuItem -label "Quicktime Movie (qt)";    //    $imgExt[7]  = "qt";   $imgExtNum[7]  = 22;
  1101.         menuItem -label "Quicktime Image (qtif)";//    $imgExt[8]  = "qtif"; $imgExtNum[8]  = 34;
  1102.         menuItem -label "Silicon Graphics (sgi)";//    $imgExt[9] = "sgi";  $imgExtNum[9]  = 5;
  1103.         menuItem -label "Targa (tga)";            //    $imgExt[10] = "tga";  $imgExtNum[10] = 19;
  1104.         menuItem -label "Tiff (tif)";            //    $imgExt[11] = "tif";  $imgExtNum[11] = 3;
  1105.         menuItem -label "Windows Bitmap (bmp)";    //    $imgExt[12] = "bmp";  $imgExtNum[12] = 20;
  1106.         optionMenuGrp -e -sl 2 hardwareImageMenu;
  1107.     }
  1108.     else 
  1109.     {
  1110.         warning "Unsupported platform in unifiedRenderGlobalsWindow.mel";
  1111.     }
  1112.  
  1113.     scriptJob 
  1114.         -parent $parent 
  1115.         -attributeChange 
  1116.             "hardwareRenderGlobals.imageFormat" 
  1117.             "updateMayaHardwareImageFormatControl";
  1118. }
  1119.  
  1120.  
  1121. global proc updateMayaHardwareImageFormatControl()
  1122. {
  1123.     string $oldParent = `setParent -query`;
  1124.     setParentToCommonTab();
  1125.  
  1126.     global string $imgExt[];  // This is the actual file extension
  1127.     global int $imgExtNum[];  // This is the corresponding internal value
  1128.  
  1129.     int $imageNum = `getAttr "hardwareRenderGlobals.imageFormat"`;
  1130.  
  1131.     for ($i=0; $i < size($imgExtNum); ++$i) 
  1132.     {
  1133.         if ($imageNum == $imgExtNum[$i]) 
  1134.         {
  1135.             optionMenuGrp -edit -sl ($i+1) hardwareImageMenu;
  1136.             enableHwMacCompressorbutton($i);
  1137.             break;
  1138.         }
  1139.     }
  1140.  
  1141.     // Update how the filename will be interpreted.
  1142.     //
  1143.     updateMayaHardwareFilenameRelatedControls;
  1144.     
  1145.     setParent $oldParent;
  1146. }
  1147.  
  1148. global proc changeMayaHardwareImageFormat()
  1149. {
  1150. //
  1151. //  Procedure Name:
  1152. //      changeImageFormat
  1153. //
  1154. //  Description:
  1155. //        This procedure is called when the user changes the type of 
  1156. //        image that will be written out.  It sets the internal 
  1157. //        representation and then updates the example to show the changes.
  1158. //
  1159.     string $oldParent = `setParent -q`;
  1160.     setParentToCommonTab();
  1161.  
  1162.     global string $imgExt[];  // This is the actual file extension
  1163.     global int $imgExtNum[];  // This is the corresponding internal value
  1164.  
  1165.     int $item = `optionMenuGrp -q -sl hardwareImageMenu` - 1; 
  1166.  
  1167.  
  1168.     setAttr hardwareRenderGlobals.imageFormat $imgExtNum[$item];
  1169.     
  1170.     enableHwMacCompressorbutton($item);
  1171.  
  1172.     // Check if the image format is IFF.
  1173.     //
  1174.     // Note: there are two IFF image types. One for 8 bit images
  1175.     // and one for 16 bit images. They both have an imgExt of iff.
  1176.  
  1177. /*        if ($imgExt[$item] != "iff") 
  1178.     {
  1179.         int $useBlur = `getAttr hardwareRenderGlobals.motionBlur`;
  1180.         int $blur2d = (`getAttr hardwareRenderGlobals.motionBlurType` == 0);
  1181.         int $keepMotionVector = (`getAttr hardwareRenderGlobals.keepMotionVector` == 1);
  1182.         if ($useBlur && $blur2d && $keepMotionVector) 
  1183.         {
  1184.             warning
  1185.                 ("Non-IFF image formats are not supported when writing"+
  1186.                  " 2D motion vectors; setting image format to IFF");
  1187.  
  1188.             // Set globals imageFormat to Maya IFF
  1189.             setAttr hardwareRenderGlobals.imageFormat 7;
  1190.         }
  1191.     }
  1192.  
  1193.     $item = `optionMenuGrp -q -sl hardwareImageMenu` - 1; 
  1194.     int $multiframe = multiframeFormat($imgExt[$item]);
  1195.  
  1196.     if ( $multiframe )
  1197.     {
  1198.         setAttr defaultRenderGlobals.animation 1;
  1199.     }
  1200.  
  1201.     // Update the batch render window if it exists.    
  1202.     if (`exists updateBatchRenderWindowTitle`) 
  1203.     {
  1204.         updateBatchRenderWindowTitle();
  1205.     }*/
  1206.  
  1207.     setParent $oldParent;
  1208. }
  1209.  
  1210.  
  1211. proc createCameraControl()
  1212. {
  1213.     //Note: not updating if changed elsewhere
  1214.     //
  1215.     optionMenuGrp 
  1216.         -label "Camera" 
  1217.         -changeCommand changeMayaHardwareCamera 
  1218.         mayaHardwareCameraMenu;
  1219. }
  1220.  
  1221.  
  1222. global proc updateMayaHardwareCameraControl()
  1223. {
  1224.     string $oldParent = `setParent -query`;
  1225.  
  1226.     setParentToCommonTab();
  1227.  
  1228.     // This is a fix to get around the optionMenuGrp bug (#81337)
  1229.     string $fullName = `setParent "mayaHardwareCameraMenu"`;
  1230.     string $menuName = ($fullName+"|OptionMenu");
  1231.     setParent -m $menuName;
  1232.  
  1233.     string $allCameras[] = `ls -cameras`;
  1234.     string $parents[];
  1235.     int    $i;
  1236.     int       $numRenderable = 0;
  1237.     string $cmd;
  1238.  
  1239.     //
  1240.     // First remove any existing menuItems; we're gonna rebuild the menu
  1241.     // from scratch each time.
  1242.  
  1243.     int $numOldMenuItems = `optionMenuGrp -q -ni mayaHardwareCameraMenu`;
  1244.     string    $oldMenuItems[] = `optionMenuGrp -q -ill mayaHardwareCameraMenu`;
  1245.  
  1246.     for ($i = 0; $i < $numOldMenuItems; $i++) 
  1247.     {
  1248.         deleteUI $oldMenuItems[$i];
  1249.     }
  1250.  
  1251.     // Run through the list of all of the cameras and build a
  1252.     // optionMenu of them that the user uses to select the
  1253.     // renderable camera.
  1254.     //
  1255.     // First count how many renderable cameras exist
  1256.     //
  1257.     for ($i = 0; $i < size($allCameras); $i++) 
  1258.     {
  1259.         if (`getAttr ($allCameras[$i] + ".renderable")`) 
  1260.         {
  1261.             $numRenderable++;
  1262.         }
  1263.     }
  1264.  
  1265.     int $firstRenderable = 0;
  1266.     for ($i = 0; $i < size($allCameras); $i++) 
  1267.     {
  1268.         $parents = `listRelatives -path -parent $allCameras[$i]`;
  1269.         string $thisLabel = `menuItem -label $parents[0]`;
  1270.         // Use the first renderable camera
  1271.         if (`getAttr ($allCameras[$i] + ".renderable")`) 
  1272.         {
  1273.             $firstRenderable++;
  1274.             if ($firstRenderable == 1) 
  1275.             {
  1276.                 // Selected Camera -----------------------------------------
  1277.                 optionMenuGrp -edit -sl ($i+1) mayaHardwareCameraMenu;
  1278.             }
  1279.             if ($numRenderable > 1) 
  1280.             {
  1281.                 string $camLabel = $parents[0] + " (Renderable)";
  1282.                 menuItem -edit -label $camLabel $thisLabel;
  1283.             }
  1284.         }
  1285.     }
  1286.  
  1287.     setParent $oldParent;
  1288. }
  1289.  
  1290. global proc changeMayaHardwareCamera()
  1291. {
  1292. //
  1293. //  Procedure Name:
  1294. //      switchCamera
  1295. //
  1296. //  Description:
  1297. //        This procedure is called when the user changes the camera
  1298. //        that will be rendered.
  1299. //        It updates the controls for the new camera
  1300. //
  1301.     string $oldParent = `setParent -q`;
  1302.     setParentToCommonTab();
  1303.  
  1304.     //
  1305.     // First count how many renderable cameras exist
  1306.     //
  1307.     string $allCameras[] = `ls -cameras`;
  1308.  
  1309.     int $numRenderable = 0;
  1310.  
  1311.     for ($i = 0; $i < size($allCameras); $i++) 
  1312.     {
  1313.         if (`getAttr ($allCameras[$i] + ".renderable")`) 
  1314.         {
  1315.             $numRenderable++;
  1316.         }
  1317.     }
  1318.  
  1319.     int $camIndex = `optionMenuGrp -query -select mayaHardwareCameraMenu` - 1;
  1320.  
  1321.     if ($numRenderable < 2) 
  1322.     {
  1323.         for ($i = 0; $i < size($allCameras); $i++) 
  1324.         {
  1325.             if ($i == $camIndex) 
  1326.             {
  1327.                 setAttr ($allCameras[$i] + ".renderable") 1;
  1328.             } 
  1329.             else 
  1330.             {
  1331.                 setAttr ($allCameras[$i] + ".renderable") 0;
  1332.             }
  1333.         }
  1334.     }
  1335.  
  1336.     // Connect the channel controls to the new camera
  1337.     //
  1338.     string $whichCamera = $allCameras[$camIndex];
  1339.     attrControlGrp -edit -attribute ($whichCamera + ".mask") alphaChannel;
  1340.     attrControlGrp -edit -attribute ($whichCamera + ".depth") depthChannel;
  1341.  
  1342.     // Fix for 160069. The mental ray renderer and the Maya renderer
  1343.     // use the same renderable camera, so the mental ray render globals and
  1344.     // the Maya render globals must be kept in sync when the renderable camera
  1345.     // changes. The following code causes the attribute editor to be 
  1346.     // refreshed, just in case it contains the mental ray render globals.
  1347.     //
  1348.     global string $gAEFocusNode;
  1349.     updateAE($gAEFocusNode);
  1350.  
  1351.     // When the camera is changed, update the example file name.
  1352.     //
  1353.     updateMayaHardwareTargetFilePreview;
  1354.  
  1355.     setParent $oldParent;
  1356. }
  1357.  
  1358. global proc changeMayaHardwareRenderableObjectCtrl()
  1359. {
  1360.     int $item = `optionMenuGrp -q -sl renderableObjectCtrl`;
  1361.  
  1362.     global string $hardwareRenderSelectedFlag;
  1363.     $hardwareRenderSelectedFlag = ""; 
  1364.  
  1365.     if ($item == 2)
  1366.     {
  1367.         $hardwareRenderSelectedFlag = "-renderSelected";
  1368.     }
  1369. }
  1370.  
  1371. proc updateMayaHardwareRenderableObjectCtrl()
  1372. {
  1373.     //
  1374.     // Description:
  1375.     //    This procedure is called when Renderable Object control needs to be
  1376.     //    refreshed.
  1377.     //    This procedure updates the Renderable Object control to reflect the
  1378.     //    current value of the flag which represents the value of the control.
  1379.     //
  1380.  
  1381.     global string $hardwareRenderSelectedFlag; 
  1382.  
  1383.     string $oldParent = `setParent -q`;
  1384.     setParentToCommonTab();
  1385.  
  1386.     if ($hardwareRenderSelectedFlag == "-renderSelected")
  1387.     {
  1388.         // Select "Render Active" in the Renderable Objects option menu
  1389.         //
  1390.         optionMenuGrp -edit -select 2 renderableObjectCtrl;
  1391.     }
  1392.     else
  1393.     {
  1394.         // Select "Render All" in the Renderable Objects option menu
  1395.         //
  1396.         optionMenuGrp -edit -select 1 renderableObjectCtrl;
  1397.     }
  1398.  
  1399.     setParent $oldParent;
  1400. }
  1401.  
  1402. // Description:  This procedure is called when we need enable/disable 
  1403. //      animation frame number or frame padding related controls.
  1404. //      
  1405. global proc updateMayaHardwareFrameNumberControls()
  1406. {
  1407.     string $oldParent = `setParent -q`;
  1408.     setParentToCommonTab();
  1409.  
  1410.     int $multiframe = checkMayaHardwareMultiframeFormat();
  1411.     int $useAnim =  `getAttr defaultRenderGlobals.animation`; 
  1412.  
  1413.     attrControlGrp -edit -enable $useAnim mayaHardwareStartFrameCtrl;
  1414.     attrControlGrp -edit -enable $useAnim mayaHardwareEndFrameCtrl;
  1415.     attrControlGrp -edit -enable $useAnim mayaHardwareByFrameCtrl;
  1416.  
  1417.     attrControlGrp -edit -enable ($useAnim && !$multiframe) 
  1418.         mayaHardwareRenumberFrameCtrl;
  1419.     intFieldGrp -edit -enable ($useAnim && !$multiframe) framePaddingCtrl;
  1420.  
  1421.  
  1422.     int $renumberFrames    = `getAttr "hardwareRenderGlobals.modifyExtension"`;
  1423.     $renumberFrames = $renumberFrames && $useAnim && !$multiframe;
  1424.  
  1425.     attrControlGrp 
  1426.         -edit
  1427.         -enable $renumberFrames
  1428.         startExtensionCtrl;
  1429.     attrControlGrp 
  1430.         -edit
  1431.         -enable $renumberFrames
  1432.         byExtensionCtrl;
  1433.  
  1434.     updateMayaHardwareTargetFilePreview();
  1435.  
  1436.     setParent $oldParent;
  1437. }
  1438.  
  1439. // Description: This procedure is called when the frame padding is changed
  1440. //      by the user from the unified render globals.
  1441. //
  1442. global proc mayaHardwareFramePaddingChanged()
  1443. {
  1444.     // If the "Frame/Animation Ext" is set to "custom", then the
  1445.     // filename == the prefix, so we need to change the frame 
  1446.     // padding information in the prefix.
  1447.     //
  1448.     int $item = `optionMenuGrp -q -sl mayaHardwareExtMenu`;
  1449.     if ($item == 9)
  1450.     {
  1451.         int $pad = `intFieldGrp -query -value1 framePaddingCtrl`;
  1452.         if ($pad < 1)
  1453.         {
  1454.             $pad = 1;
  1455.             intFieldGrp -edit -value1 $pad framePaddingCtrl;
  1456.         }
  1457.  
  1458.         string $prefix = `textFieldGrp -query -text mayaHardwareFilePrefix`;
  1459.         $prefix = changeFramePaddingInfoInFilename($prefix, $pad);
  1460.         textFieldGrp -edit -text $prefix mayaHardwareFilePrefix;
  1461.     }
  1462.             
  1463.     mayaHardwareFilenameChange; 
  1464.     updateMayaHardwareTargetFilePreview;
  1465. }
  1466.  
  1467. proc createCommonImageFile() 
  1468. //
  1469. //  Procedure Name:
  1470. //      createCommonImageFile
  1471. //
  1472. //  Description:
  1473. //      Creates the UI in the "Image File Output" expand/collapse section.
  1474. //        This section is always created so is treated differently
  1475. //        then the sections created when the tab is expanded.
  1476. //
  1477. {
  1478.     string $parent = `setParent -query`;
  1479.  
  1480.     setUITemplate -pushTemplate attributeEditorTemplate;
  1481.  
  1482.     global string $imgExt[];
  1483.  
  1484.     if (size( $imgExt ) == 0)
  1485.     {
  1486.         // If the file format array has not been initialized yet, do so.
  1487.         // This routine may be called in dynPaintMenus.mel during the
  1488.         // file save for PFX canvas images.
  1489.         createImageFormats();
  1490.     }
  1491.     
  1492.     columnLayout -adjustableColumn true;
  1493.  
  1494.         createFileNamePrefixControl();
  1495.         createFileNameFormatControl();
  1496.         createImageFormatControl();
  1497.         if(`about -mac`){
  1498.             int $item = `optionMenuGrp -q -sl hardwareImageMenu` - 1; 
  1499.             createHwCompressorControlForMac($item);
  1500.         }
  1501.  
  1502.         separator;
  1503.     
  1504.         // Frame numbers ------------------------------------------------
  1505.  
  1506.         attrControlGrp 
  1507.             -attribute hardwareRenderGlobals.startFrame 
  1508.             -cc "updateMayaHardwareTargetFilePreview"
  1509.             -hideMapButton true
  1510.             -label "Start Frame"
  1511.             mayaHardwareStartFrameCtrl;
  1512.         attrControlGrp 
  1513.             -attribute hardwareRenderGlobals.endFrame 
  1514.             -cc "updateMayaHardwareTargetFilePreview"
  1515.             -hideMapButton true
  1516.             -label "End Frame"
  1517.             mayaHardwareEndFrameCtrl;
  1518.         attrControlGrp 
  1519.             -attribute hardwareRenderGlobals.byFrame
  1520.             -hideMapButton true
  1521.             -label "By Frame"
  1522.             mayaHardwareByFrameCtrl;
  1523.  
  1524.         intFieldGrp 
  1525.             -label "Frame Padding"
  1526.             -value1 1
  1527.             -cc "mayaHardwareFramePaddingChanged()"
  1528.             framePaddingCtrl;
  1529.  
  1530.         separator;
  1531.     
  1532.         // Renderable Objects ------------------------------------------------
  1533.  
  1534.         optionMenuGrp
  1535.             -label "Renderable Objects" 
  1536.             -cc "changeMayaHardwareRenderableObjectCtrl"
  1537.             renderableObjectCtrl;
  1538.         
  1539.             menuItem -label "Render All";
  1540.             menuItem -label "Render Active";
  1541.  
  1542.         changeMayaHardwareRenderableObjectCtrl();
  1543.  
  1544.         // Cameras ------------------------------------------------
  1545.  
  1546.         createCameraControl();
  1547.         updateMayaHardwareCameraControl();
  1548.  
  1549.         // Channels ------------------------------------------------
  1550.  
  1551.         string $currentCamera = `optionMenuGrp -q -v mayaHardwareCameraMenu`; 
  1552.         //
  1553.         // Remove the substring " (Renderable)" from the string 
  1554.         // $currentCamera if there is any. 
  1555.         //
  1556.         $currentCamera = `substitute " .*" $currentCamera ""`;
  1557.         string $camShapes[] = `listRelatives -path -shapes $currentCamera`;
  1558.         $currentCamera = $camShapes[0];
  1559.  
  1560.         // With the Maya Hardware Renderer, you do not have the option of 
  1561.         // not outputting color. Therefore we will show the user that the color
  1562.         // channel is on, but we won't allow them to change it.
  1563.         //
  1564.         checkBoxGrp
  1565.                 -label "Channels"
  1566.                 -label1 "RGB Channel (Color)"
  1567.                 -ann "Not available for this renderer"
  1568.                 -value1 true -enable false;
  1569.  
  1570.         attrControlGrp
  1571.                 -label "Alpha Channel (Mask)"
  1572.                 -attribute ($currentCamera + ".mask")
  1573.                 alphaChannel;
  1574.         attrControlGrp
  1575.                 -label "Depth Channel (Z Depth)"
  1576.                 -attribute ($currentCamera + ".depth")
  1577.                 depthChannel;
  1578.  
  1579.         // The Maya Hardware Renderer does not support a custom extension, so
  1580.         // although we create controls for custom extension which look the same
  1581.         // as they do for other renderers, these controls will remain disabled.
  1582.         //
  1583.         frameLayout
  1584.             -collapsable true
  1585.             -collapse true
  1586.             -label "Custom Extension";
  1587.  
  1588.             columnLayout;
  1589.  
  1590.                 attrControlGrp
  1591.                         -cc "updateMayaHardwareCustomExtension"
  1592.                         -attribute hardwareRenderGlobals.useCustomExtension
  1593.                         mayaHardwareUseCustomExtionsionCtrl;
  1594.  
  1595.                 attrControlGrp
  1596.                         -label ""
  1597.                         -attribute hardwareRenderGlobals.customExtension
  1598.                         mayaHardwareCustomExtensionCtrl;
  1599.  
  1600.                         
  1601.                 updateMayaHardwareCustomExtension();
  1602.  
  1603.             setParent ..;
  1604.         setParent ..;
  1605.  
  1606.         // Frame renumbering tab
  1607.         //
  1608.         frameLayout
  1609.             -collapsable true
  1610.             -collapse true
  1611.             -label "Renumber Frames";
  1612.  
  1613.             columnLayout;
  1614.                 attrControlGrp
  1615.                     -attribute hardwareRenderGlobals.modifyExtension
  1616.                     -changeCommand "updateMayaHardwareFrameNumberControls"
  1617.                     -label "Renumber Frames Using:"
  1618.                     mayaHardwareRenumberFrameCtrl;
  1619.                 attrControlGrp
  1620.                     -attribute hardwareRenderGlobals.startExtension
  1621.                     -enable (`getAttr hardwareRenderGlobals.modifyExtension`)
  1622.                     -cc "updateMayaHardwareTargetFilePreview"
  1623.                     -hideMapButton true
  1624.                     -label "Start Number" startExtensionCtrl;
  1625.                 attrControlGrp
  1626.                     -attribute hardwareRenderGlobals.byExtension
  1627.                     -enable (`getAttr hardwareRenderGlobals.modifyExtension`)
  1628.                     -cc "updateMayaHardwareTargetFilePreview"
  1629.                     -hideMapButton true
  1630.                     -label "By Frame" byExtensionCtrl;
  1631.             setParent ..;
  1632.         setParent ..;
  1633.  
  1634.     setParent $parent;
  1635.     setUITemplate -popTemplate;
  1636.  
  1637.     // Perform an initial update of the UI created above, so that controls
  1638.     // which are not directly connected to attributes are properly initialized.
  1639.     //
  1640.     updateMayaHardwareFilenameRelatedControls;
  1641.     updateMayaHardwareImageFormatControl();
  1642.     // updateMayaHardwareUseCustomExtensionControl();
  1643.     // updateMayaHardwareCustomExtensionControl();
  1644. //    updateMayaHardwareAlphaChannelControl();
  1645. //    updateMayaHardwareDepthChannelControl();
  1646. }
  1647.  
  1648. global proc updateMayaHardwareCustomExtension()
  1649. {
  1650.     string $oldParent = `setParent -q`;
  1651.     setParentToCommonTab();
  1652.  
  1653.     // When the "Frame/Animation Ext" does not involve frame extension,
  1654.     // gray out "Using Custom Extension".
  1655.     //
  1656.     int $useExtension = true;
  1657.     int $item = `optionMenuGrp -q -select mayaHardwareExtMenu`;
  1658.     if ($item == 1 || $item == 5)
  1659.     {
  1660.         $useExtension = false;
  1661.     } 
  1662.  
  1663.     attrControlGrp -edit -enable $useExtension 
  1664.         mayaHardwareUseCustomExtionsionCtrl;
  1665.     
  1666.     // The custom extension field is enabled only when we need frame
  1667.     // extension and the "Use Custom Extension" is on.
  1668.     //
  1669.     int $modifyExt = `getAttr hardwareRenderGlobals.useCustomExtension`;
  1670.     $modifyExt = $modifyExt && $useExtension;
  1671.     attrControlGrp -edit -enable $modifyExt mayaHardwareCustomExtensionCtrl;
  1672.     
  1673.     setParent $oldParent;
  1674. }
  1675.  
  1676. //==================================================================
  1677. // Hardware Common Tab
  1678. //==================================================================
  1679.  
  1680. global proc updateMayaHardwareCommonGlobalsTab()
  1681. {
  1682.     //
  1683.     // Description:
  1684.     //    This procedure is called when the current renderer changes to be the
  1685.     //    Maya Hardware Renderer.
  1686.     //    This procedure updates the UI of the common tab to reflect any values
  1687.     //    which may have been copied from the previous current renderer.
  1688.     //
  1689.  
  1690.     updateMayaHardwareFilenameRelatedControls;
  1691.     updateMayaHardwareRenderableObjectCtrl();
  1692.     updateMayaHardwareCameraControl();
  1693.     updateMayaHardwareResolution();
  1694.     updateMayaHardwareTargetFilePreview();
  1695. }
  1696.  
  1697. // ----------------------------------------------------------------------------
  1698. // Code to create and update the Render Options frame 
  1699. //
  1700. proc createMayaHardwareCommonRenderOptions()
  1701. {
  1702.     string $parent = `setParent -query`;
  1703.  
  1704.     setUITemplate -pushTemplate attributeEditorTemplate;
  1705.     
  1706.     columnLayout -adjustableColumn true;
  1707.     
  1708.         attrControlGrp 
  1709.             -attribute "hardwareRenderGlobals.enableDefaultLight"; 
  1710.         
  1711.         textFieldGrp -label "Plug-in Format"
  1712.             -tx "Not available for this renderer"
  1713.             -enable false;
  1714.  
  1715.         attrControlGrp 
  1716.             -attribute hardwareRenderGlobals.preRenderMel 
  1717.             -label "Pre Render MEL"
  1718.             preRenderMelHwGrp;
  1719.             
  1720.         attrControlGrp 
  1721.             -attribute hardwareRenderGlobals.postRenderMel
  1722.             -label "Post Render MEL"
  1723.             postRenderMelHwGrp;
  1724.             
  1725.         if (`about -evalVersion`)
  1726.         {
  1727.             attrControlGrp -e -enable false preRenderMelHwGrp;
  1728.             attrControlGrp -e -enable false postRenderMelHwGrp;
  1729.         }
  1730.  
  1731.     setParent $parent;
  1732.     setUITemplate -popTemplate;
  1733. }
  1734.  
  1735. global proc createMayaHardwareCommonGlobalsTab()
  1736. {
  1737.     //
  1738.     // Description:
  1739.     //    This procedure builds the "Common" tab for the Maya Hardware renderer.
  1740.     //
  1741.  
  1742.     string $renderer = "mayaHardware";
  1743.  
  1744.     string $parentForm = `setParent -query`;
  1745.  
  1746.         createTargetFilePreview();
  1747.  
  1748.     setParent $parentForm;
  1749.  
  1750.     scrollLayout 
  1751.         -horizontalScrollBarThickness 0 
  1752.         scrollLayout;
  1753.  
  1754.         columnLayout 
  1755.             -adjustableColumn true
  1756.             commonTabColumn;
  1757.  
  1758.             // Image File Name
  1759.             //
  1760.             frameLayout 
  1761.                 -label "Image File Output" 
  1762.                 -collapsable true 
  1763.                 -collapse false
  1764.                 rgImageFileFrame;
  1765.             
  1766.                 createCommonImageFile();
  1767.  
  1768.             setParent commonTabColumn;
  1769.  
  1770.             // Resolution Section
  1771.             //
  1772.             frameLayout 
  1773.                 -label "Resolution" 
  1774.                 -collapsable true 
  1775.                 -collapse false 
  1776.                 rgResolutionFrame;
  1777.  
  1778.                 createMayaHardwareCommonResolution();
  1779.  
  1780.             setParent commonTabColumn;
  1781.  
  1782.             // Render Options
  1783.             //
  1784.             frameLayout 
  1785.                 -label "Render Options" 
  1786.                 -collapsable true 
  1787.                 -collapse false 
  1788.                 rgOptionFrame;
  1789.  
  1790.                 createMayaHardwareCommonRenderOptions(); 
  1791.  
  1792.             setParent commonTabColumn;
  1793.  
  1794.     setParent $parentForm;
  1795.  
  1796.     formLayout
  1797.         -edit 
  1798.         -af mayaHardwareTargetFilePreview "top" 5
  1799.         -an mayaHardwareTargetFilePreview "bottom" 
  1800.         -af mayaHardwareTargetFilePreview "left" 0
  1801.         -af mayaHardwareTargetFilePreview "right" 0
  1802.         -ac scrollLayout "top" 5 mayaHardwareTargetFilePreview
  1803.         -af scrollLayout "bottom" 0
  1804.         -af scrollLayout "left" 0
  1805.         -af scrollLayout "right" 0
  1806.         $parentForm;
  1807.  
  1808.     // Update the TargetFilePreview at the end, because it
  1809.     // uses a number of controls in the Image File Output 
  1810.     // frame.
  1811.     //
  1812.     updateMayaHardwareTargetFilePreview();
  1813. }
  1814.  
  1815. // ----------------------------------------------------------------------------
  1816. // Code to create and update the Resolution frame 
  1817. //
  1818.  
  1819. global proc createMayaHardwareCommonResolution()
  1820. //
  1821. //  Procedure Name:
  1822. //      createMayaHardwareCommonResolution
  1823. //
  1824. //  Description:
  1825. //      Creates the UI in the "Resolution" expand/collapse section.
  1826. //
  1827. {
  1828.     //
  1829.     // Make sure the list of predefined resolutions has been read in.
  1830.     //
  1831.     global string   $gImageFormatData[];
  1832.     global string   $gUserImageFormatData[];
  1833.  
  1834.     if (size($gImageFormatData) == 0) 
  1835.     {
  1836.         eval("source imageFormats");
  1837.     }
  1838.  
  1839.     int $isMayaEvalVersion = `about -ev`;
  1840.     global string   $gPLEImageFormatData[];
  1841.     if ($isMayaEvalVersion) 
  1842.     {
  1843.         $gImageFormatData = $gPLEImageFormatData;
  1844.     }
  1845.  
  1846.     if (exists("userImageFormats.mel") && size($gUserImageFormatData) == 0) 
  1847.     {
  1848.         // Yes, we need the eval here, to avoid doing the source
  1849.         // until we know whether the file actually exists
  1850.         eval("source userImageFormats");
  1851.     }
  1852.  
  1853.     setUITemplate -pushTemplate attributeEditorTemplate;
  1854.  
  1855.     // If the UI is created already then just update the attribute values.
  1856.     if (`columnLayout -exists rgMayaHardwareResolutionLayout`) 
  1857.     {
  1858.         updateMayaHardwareResolution;
  1859.         return;
  1860.     }
  1861.  
  1862.     columnLayout -adjustableColumn true rgMayaHardwareResolutionLayout;
  1863.         int        $resItem;
  1864.         int        $numResolutionPresets = size($gImageFormatData);
  1865.         int        $numUserResolutionPresets = size($gUserImageFormatData);
  1866.         string  $allResNodes[] = `ls -type resolution`;
  1867.         int        $numResolutionNodePresets = size($allResNodes) - 1;
  1868.         int        $numTokens;
  1869.         string    $tokens[];
  1870.         string  $niceName;
  1871.         int     $enablePresetItem;
  1872.         int     $presetWidth;
  1873.         int     $presetHeight;
  1874.  
  1875.         optionMenuGrp 
  1876.             -label "Presets" 
  1877.             -changeCommand "changeMayaHardwareResolution" 
  1878.             resolutionMenu;
  1879.  
  1880.             menuItem -label "Custom";
  1881.             for ($resItem = 0; $resItem < $numResolutionPresets; $resItem++) 
  1882.             {
  1883.                 string $item = $gImageFormatData[$resItem];
  1884.                 $numTokens = tokenize($item, $tokens);
  1885.  
  1886.                 // Change any underscore into a space;
  1887.                 // some names may have up to 2 underscores in them,
  1888.                 // so we do this twice.
  1889.                 //
  1890.                 $niceName = `substitute "_" $tokens[0] " "`;
  1891.                 $niceName = `substitute "_" $niceName " "`;
  1892.         
  1893.                 // Grey out the presets where the width or the height
  1894.                 // is more than 2048 for hardware rendering.  
  1895.                 // 
  1896.                 $presetWidth  = $tokens[1];
  1897.                 $presetHeight = $tokens[2];
  1898.                 $enablePresetItem = true;         
  1899.                 if ($presetWidth > 2048 || $presetHeight > 2048)
  1900.                 {
  1901.                     $enablePresetItem = false;         
  1902.                 }
  1903.                 menuItem -label $niceName -enable $enablePresetItem;
  1904.             }
  1905.             for ($resItem = 0; $resItem < $numUserResolutionPresets; $resItem++)
  1906.             {
  1907.                 string $item = $gUserImageFormatData[$resItem];
  1908.                 $numTokens = tokenize($item, $tokens);
  1909.  
  1910.                 // Change any underscore into a space;
  1911.                 // some names may have up to 2 underscores in them,
  1912.                 // so we do this twice.
  1913.                 //
  1914.                 $niceName = `substitute "_" $tokens[0] " "`;
  1915.                 $niceName = `substitute "_" $niceName " "`;
  1916.  
  1917.                 // Grey out the presets where the width or the height
  1918.                 // is more than 2048 for hardware rendering.  
  1919.                 // 
  1920.                 $presetWidth  = $tokens[1];
  1921.                 $presetHeight = $tokens[2];
  1922.                 $enablePresetItem = true;         
  1923.                 if ($presetWidth > 2048 || $presetHeight > 2048)
  1924.                 {
  1925.                     $enablePresetItem = false;         
  1926.                 }
  1927.                 
  1928.                 menuItem -label $niceName -enable $enablePresetItem;
  1929.             }
  1930.             for ($resItem = 0; $resItem < $numResolutionNodePresets; $resItem++)
  1931.             {
  1932.                 menuItem -label $allResNodes[$resItem + 1];
  1933.             }
  1934.  
  1935.         separator;
  1936.         
  1937.         // This attribute is not yet supported by the Maya Hardware Renderer.
  1938.         // Once it becomes supported, this control can be enabled, updated, and
  1939.         // hooked up with a change command.
  1940.         // 
  1941.         checkBoxGrp -numberOfCheckBoxes 1
  1942.             -label1 "Maintain Width/Height Ratio"
  1943.             -value1 false
  1944.             -cc "checkMayaHardwareAspectLock"
  1945.             aspectLockCheck;
  1946.  
  1947.         intFieldGrp -label "Width" 
  1948.             -changeCommand "changeMayaHardwareAspectLockWidth"
  1949.             mayaHardwareResWidth;
  1950.         intFieldGrp -label "Height" 
  1951.             -changeCommand "changeMayaHardwareAspectLockHeight"
  1952.             mayaHardwareResHeight;
  1953.  
  1954.         scriptJob
  1955.             -parent mayaHardwareResWidth
  1956.             -attributeChange 
  1957.                 "hardwareRenderGlobals.resolutionX"
  1958.                 "intFieldGrp -e -v1 `getAttr hardwareRenderGlobals.resolutionX` mayaHardwareResWidth; changeMayaHardwareAspectLockWidth";
  1959.  
  1960.         scriptJob
  1961.             -parent mayaHardwareResHeight
  1962.             -attributeChange 
  1963.                 "hardwareRenderGlobals.resolutionY"
  1964.                 "intFieldGrp -e -v1 `getAttr hardwareRenderGlobals.resolutionY` mayaHardwareResHeight; changeMayaHardwareAspectLockHeight";
  1965.  
  1966.         separator;
  1967.  
  1968.         // This attribute is not yet supported by the Maya Hardware Renderer.
  1969.         // Once it becomes supported, this control can be enabled, updated, and
  1970.         // hooked up with a change command.
  1971.         // 
  1972.         checkBoxGrp 
  1973.             -annotation "Not available for this renderer"
  1974.             -enable false
  1975.             -numberOfCheckBoxes 1
  1976.             -label1 "Lock Device Aspect Ratio" 
  1977.             -value1 false
  1978.             ratioLockCheck;
  1979.  
  1980.         // This attribute is not yet supported by the Maya Hardware Renderer.
  1981.         // Once it becomes supported, this control can be enabled, updated, and
  1982.         // hooked up with a change command.
  1983.         //
  1984.         floatFieldGrp 
  1985.             -annotation "Not available for this renderer"
  1986.             -label "Device Aspect Ratio"  
  1987.             -enable false
  1988.             -numberOfFields 1
  1989.             resRatio;
  1990.  
  1991.         // This attribute is not yet supported by the Maya Hardware Renderer.
  1992.         // Once it becomes supported, this control can be enabled, updated, and
  1993.         // hooked up with a change command.
  1994.         // 
  1995.         attrControlGrp 
  1996.             -attribute "hardwareRenderGlobals.pixelAspectRatio"
  1997.             -hideMapButton true
  1998.             -changeCommand "adjustMayaHardwareDeviceAspect; updateMayaHardwareResolution"; 
  1999.  
  2000.         adjustMayaHardwareDeviceAspect();
  2001.  
  2002.         // Temporary fix for bug 184921:
  2003.         // Set up script job for resolution gate update.
  2004.         // 
  2005.         string $attrArray[];
  2006.  
  2007.         $attrArray[size($attrArray)] = 
  2008.             "hardwareRenderGlobals.resolutionX";
  2009.         $attrArray[size($attrArray)] = 
  2010.             "hardwareRenderGlobals.resolutionY";
  2011.         $attrArray[size($attrArray)] = 
  2012.             "hardwareRenderGlobals.pixelAspectRatio";
  2013.  
  2014.         // Now we establish scriptJobs to invoke the procedure 
  2015.         // which updates the maya software attribute that effects the 
  2016.         // "camera settings --> resolution gate".
  2017.         //
  2018.         int $i;
  2019.  
  2020.         for ($i = 0; $i < size($attrArray); $i++)
  2021.         {
  2022.             scriptJob
  2023.                 -attributeChange 
  2024.                     $attrArray[$i]
  2025.                     "copyAttrForResolutionGate(\"mayaHardware\")"
  2026.                 -parent rgMayaHardwareResolutionLayout;
  2027.         }
  2028.  
  2029.     setParent ..;
  2030.     setUITemplate -popTemplate;
  2031.  
  2032.     // Make sure the values are right
  2033.     updateMayaHardwareResolution;
  2034.  
  2035.     // Make sure the values are updated on file new
  2036.     //
  2037.     scriptJob
  2038.         -parent `setParent -query` 
  2039.         -event "NewSceneOpened" "updateMayaHardwareResolution";
  2040. }
  2041.  
  2042.  
  2043. global proc updateMayaHardwareResolution()
  2044. //
  2045. //  Procedure Name:
  2046. //      updateResolution
  2047. //
  2048. //  Description:
  2049. //      Gets the real values from the nodes and sets the UI based
  2050. //        on these values.  This procedure updates all of the resolution
  2051. //        values.
  2052. //
  2053. {
  2054.     string $oldParent = `setParent -q`;
  2055.     setParentToCommonTab();
  2056.  
  2057.     int $width = `getAttr hardwareRenderGlobals.resolutionX`;
  2058.     int $height = `getAttr hardwareRenderGlobals.resolutionY`;
  2059.     float $deviceAspectRatio= `getAttr hardwareRenderGlobals.pixelAspectRatio`;
  2060.     $deviceAspectRatio *= $width;
  2061.     $deviceAspectRatio /= $height;
  2062.  
  2063.     int $resItem;
  2064.     int $whichRes = 1; // use "Custom" if no match is found
  2065.     string $allResNodes[] = `ls -type resolution`;
  2066.  
  2067.     global string   $gImageFormatData[];
  2068.     global string   $gUserImageFormatData[];
  2069.     int        $numResolutionPresets = size($gImageFormatData);
  2070.     int        $numUserResolutionPresets = size($gUserImageFormatData);
  2071.     int        $numResolutionNodePresets = size($allResNodes) - 1;
  2072.     int        $resWidth;
  2073.     int        $resHeight;
  2074.     float    $resAspect;
  2075.     int        $numTokens;
  2076.     string    $tokens[];
  2077.  
  2078.     for ($resItem = 0; $resItem < $numResolutionPresets; $resItem++) 
  2079.     {
  2080.         string $item = $gImageFormatData[$resItem];
  2081.         $numTokens = tokenize($item, $tokens);
  2082.         if ($numTokens == 4) 
  2083.         {
  2084.             $resWidth = $tokens[1];
  2085.             $resHeight = $tokens[2];
  2086.             $resAspect = $tokens[3];
  2087.             if ($width == $resWidth && $height == $resHeight
  2088.                     && abs($deviceAspectRatio - $resAspect) < 0.001) 
  2089.             {
  2090.                 // We add _2_ to $resItem below: 1 because we're
  2091.                 // skipping the first item (Custom) in the list, and 1
  2092.                 // because the optionMenu items are numbered starting at 1,
  2093.                 // but our list in $gImageFormatData is indexed starting at 0.
  2094.                 $whichRes = $resItem + 2;
  2095.                 break;
  2096.             }
  2097.         } 
  2098.         else 
  2099.         {
  2100.             warning(
  2101.                 "Found invalid image format description: \""
  2102.                 + $item 
  2103.                 + "\" in imageFormats.mel");
  2104.         }
  2105.     }
  2106.  
  2107.     // If no match was found in the built-in resolutions,
  2108.     // check out the user-defined ones
  2109.     //
  2110.     if ($whichRes == 1) 
  2111.     {
  2112.         for ($resItem = 0; $resItem < $numUserResolutionPresets; $resItem++) 
  2113.         {
  2114.             string $item = $gUserImageFormatData[$resItem];
  2115.             $numTokens = tokenize($item, $tokens);
  2116.             if ($numTokens == 4) 
  2117.             {
  2118.                 $resWidth = $tokens[1];
  2119.                 $resHeight = $tokens[2];
  2120.                 $resAspect = $tokens[3];
  2121.  
  2122.                 if ($width == $resWidth && $height == $resHeight
  2123.                         && abs($deviceAspectRatio - $resAspect) < 0.001) 
  2124.                 {
  2125.                     $whichRes = $numResolutionPresets + $resItem + 2;
  2126.                     break;
  2127.                 }
  2128.             } 
  2129.             else 
  2130.             {
  2131.                 warning(
  2132.                     "Found invalid image format description: \""
  2133.                     + $item 
  2134.                     + "\" in userImageFormats.mel");
  2135.             }
  2136.         }
  2137.     }
  2138.  
  2139.     // If no match was found in the user-defined resolutions,
  2140.     // see if there are any 'extra' resolution nodes in the scene.
  2141.     //
  2142.     if ($whichRes == 1) 
  2143.     {
  2144.         for ($resItem = 0; $resItem < $numResolutionNodePresets; $resItem++) 
  2145.         {
  2146.             // We assume the 0th item in the list of resolution nodes is
  2147.             // the default one, which is created implicitly...
  2148.             //
  2149.             string $resNodeName = $allResNodes[$resItem + 1];
  2150.  
  2151.             $resWidth = `getAttr ($resNodeName + ".resolutionX")`;
  2152.             $resHeight = `getAttr ($resNodeName + ".resolutionY")`;
  2153.             $resAspect = `getAttr ($resNodeName + ".deviceAspectRatio")`;
  2154.  
  2155. //            if ($width == $resWidth && $height == $resHeight
  2156. //                    && abs($deviceAspectRatio - $resAspect) < 0.001) 
  2157.             if ($width == $resWidth && $height == $resHeight)
  2158.             {
  2159.                 // We add _2_ to $resItem below: 1 because we're
  2160.                 // skipping the first item (Custom) in the list, and 1
  2161.                 // because the optionMenu items are numbered starting at 1,
  2162.                 // but our list in $gImageFormatData is indexed starting at 0.
  2163.                 //
  2164.                 $whichRes = $numResolutionPresets
  2165.                             + $numUserResolutionPresets + $resItem + 2;
  2166.                 break;
  2167.             }
  2168.         }
  2169.     }
  2170.     optionMenuGrp -edit -sl $whichRes resolutionMenu;
  2171.  
  2172.     intFieldGrp -edit -v1 $width mayaHardwareResWidth;
  2173.     intFieldGrp -edit -v1 $height mayaHardwareResHeight;
  2174.     // floatFieldGrp -edit -v1 $deviceAspectRatio resRatio;
  2175.  
  2176.     setParent $oldParent;
  2177. }
  2178.  
  2179. global proc changeMayaHardwareResolution()
  2180. //
  2181. //  Procedure Name:
  2182. //      changeResolution
  2183. //
  2184. //  Description:
  2185. //        This procedure is called when the user selects a different
  2186. //        resolution.  It sets the internal representation
  2187. //        and then updates the example to show the changes.
  2188. //
  2189. {
  2190.     string $oldParent = `setParent -q`;
  2191.     setParentToCommonTab();
  2192.  
  2193.     global string   $gImageFormatData[];
  2194.     global string   $gUserImageFormatData[];
  2195.     int        $numResolutionPresets = size($gImageFormatData);
  2196.     int        $numUserResolutionPresets = size($gUserImageFormatData);
  2197.     string $allResNodes[] = `ls -type resolution`;
  2198.     int        $numResolutionNodePresets = size($allResNodes) - 1;
  2199.     string    $tokens[];
  2200.     int        $resItem = `optionMenuGrp -q -sl resolutionMenu`; 
  2201.     int        $resWidth;
  2202.     int        $resHeight;
  2203.     float    $resAspect;
  2204.     string    $item;
  2205.  
  2206.     // Item #1 is Custom, which doesn't change the fields
  2207.     // We subtract _2_ from $resItem below: 1 because we're
  2208.     // skipping the first item (Custom) in the list, and 1
  2209.     // because the optionMenu items are numbered starting at 1,
  2210.     // but our list in $gImageFormatData is indexed starting at 0.
  2211.     //
  2212.     if ($resItem > 1) 
  2213.     {
  2214.         if ($resItem > ($numResolutionPresets + 1)) 
  2215.         {
  2216.             if ($resItem
  2217.                     > ($numResolutionPresets + $numUserResolutionPresets + 1)) 
  2218.             {
  2219.                 // It's one of the user-defined resolution nodes' presets
  2220.                 string $resNodeName = $allResNodes[$resItem
  2221.                                                 - $numResolutionPresets
  2222.                                                 - $numUserResolutionPresets
  2223.                                                 - 1];
  2224.                 $resWidth = `getAttr ($resNodeName + ".resolutionX")`;
  2225.                 $resHeight = `getAttr ($resNodeName + ".resolutionY")`;
  2226.                 $resAspect = `getAttr ($resNodeName + ".deviceAspectRatio")`;
  2227.             } 
  2228.             else 
  2229.             {
  2230.                 // It's one of the user-defined resolution presets
  2231.                 $item = $gUserImageFormatData[$resItem
  2232.                     - $numResolutionPresets - 2];
  2233.                 int        $numTokens = tokenize($item, $tokens);
  2234.                 $resWidth = $tokens[1];
  2235.                 $resHeight = $tokens[2];
  2236.                 $resAspect = $tokens[3];
  2237.             }
  2238.         } 
  2239.         else 
  2240.         {
  2241.             // It's one of the built-in resolution presets
  2242.             $item = $gImageFormatData[$resItem - 2];
  2243.             int        $numTokens = tokenize($item, $tokens);
  2244.             $resWidth = $tokens[1];
  2245.             $resHeight = $tokens[2];
  2246.             $resAspect = $tokens[3];
  2247.         }
  2248.  
  2249.         $pixAspect = $resAspect * ((float)$resHeight) / ((float)$resWidth);
  2250.         
  2251.         global float $deviceAspect;
  2252.         if ($deviceAspect != 0)
  2253.             $deviceAspect = (float)$resHeight / (float)$resWidth;
  2254.  
  2255.         setAttr "hardwareRenderGlobals.resolutionX" $resWidth;
  2256.         setAttr "hardwareRenderGlobals.resolutionY" $resHeight;
  2257.         setAttr "hardwareRenderGlobals.pixelAspectRatio" $pixAspect;
  2258.     }
  2259.  
  2260.     updateMayaHardwareResolution;
  2261.  
  2262.     setParent $oldParent;
  2263. }
  2264.  
  2265. global proc checkMayaHardwareAspectLockWidth()
  2266. {
  2267.     string $nodeName = "hardwareRenderGlobals";
  2268.     float $deviceAspect;
  2269.  
  2270.     if (`checkBoxGrp -query -v1 aspectLockCheck`)
  2271.     {
  2272.         int $value = `getAttr ($nodeName + ".resolutionX")`;
  2273.     
  2274.         global float $deviceAspect;
  2275.         float $aspect = $deviceAspect;
  2276.  
  2277.         if ($aspect > 0.0)
  2278.         {
  2279.             int $rez = $aspect * $value;
  2280.             int $oldrez = `getAttr ($nodeName + ".resolutionY")`;
  2281.             if ($rez != $oldrez) 
  2282.             {
  2283.                 setAttr ($nodeName + ".resolutionY") $rez;
  2284.             }
  2285.         } 
  2286.         else 
  2287.         {
  2288.             checkMayaHardwareAspectLock; 
  2289.         }
  2290.     }
  2291. }
  2292.  
  2293. global proc checkMayaHardwareAspectLockHeight()
  2294. {
  2295.     string $nodeName = "hardwareRenderGlobals";
  2296.     float $deviceAspect;
  2297.  
  2298.     if (`checkBoxGrp -query -v1 aspectLockCheck`)
  2299.     {
  2300.         int $value = `getAttr ($nodeName + ".resolutionY")`;
  2301.         
  2302.         global float $deviceAspect;
  2303.         float $aspect = $deviceAspect;
  2304.  
  2305.         if ($aspect > 0.0)
  2306.         {
  2307.             int $rez = $value / $aspect;
  2308.             int $oldrez = `getAttr ($nodeName + ".resolutionX")`;
  2309.             if ($rez != $oldrez)
  2310.             {
  2311.                 setAttr ($nodeName + ".resolutionX") $rez;
  2312.             }
  2313.         }
  2314.         else
  2315.         {
  2316.             checkMayaHardwareAspectLock;
  2317.         }
  2318.     }
  2319. }
  2320.  
  2321. global proc checkMayaHardwareAspectLock()
  2322. {
  2323.     string $nodeName = "hardwareRenderGlobals";
  2324.     
  2325.     int $lockOn = `checkBoxGrp -query -v1 aspectLockCheck`;
  2326.     global float $deviceAspect;
  2327.  
  2328.     if ($lockOn)
  2329.     {
  2330.         float $h = `getAttr ($nodeName + ".resolutionY")`;
  2331.         float $w = `getAttr ($nodeName + ".resolutionX")`;
  2332.         float $aspect = $h / $w;
  2333.  
  2334.         $deviceAspect = $aspect;        
  2335.     }
  2336.     else
  2337.     {
  2338.         $deviceAspect = 0;
  2339.     }
  2340. }
  2341.  
  2342. global proc changeMayaHardwareAspectLockWidth()
  2343. //
  2344. //  Procedure Name:
  2345. //      changeAspectLockWidth
  2346. //
  2347. //  Description:
  2348. //        This procedure is called when the user changes the
  2349. //        resolution width.  It sets the internal representation
  2350. //        then looks at the ratio lock etc and changes any other 
  2351. //        values that rely on it. 
  2352. //
  2353. {
  2354.     string $oldParent = `setParent -q`;
  2355.     setParentToCommonTab();
  2356.  
  2357.     int $requestedWidth = `intFieldGrp -q -v1 mayaHardwareResWidth`;
  2358.     int $isMayaEvalVersion = `about -ev`;
  2359.     if ($isMayaEvalVersion)
  2360.     {
  2361.         int $kPLEMaxX = 1024;
  2362.         int $kPLEMaxY =  768;
  2363.         if ($requestedWidth > $kPLEMaxX)
  2364.         {
  2365.             warning("Image resolution is limited to "+$kPLEMaxX+"x"+$kPLEMaxY+" pixels for the Maya Personal Learning Edition");
  2366.             $requestedWidth = $kPLEMaxX;
  2367.         }
  2368.  
  2369.         if (`checkBoxGrp -query -v1 aspectLockCheck`)
  2370.         {
  2371.             global float $deviceAspect;
  2372.             float $aspect = $deviceAspect;
  2373.  
  2374.             if ($aspect > 0.0)
  2375.             {
  2376.                 int $rez = $aspect * $requestedWidth;
  2377.                 int $oldrez = `getAttr hardwareRenderGlobals.resolutionY`;
  2378.                 if (($rez <= $kPLEMaxY) && ($rez != $oldrez))
  2379.                 {
  2380.                     setAttr hardwareRenderGlobals.resolutionY $rez;
  2381.                 }
  2382.                 else
  2383.                 {
  2384.                     intFieldGrp -e -v1 $kPLEMaxY mayaHardwareResHeight;
  2385.                     changeMayaHardwareAspectLockHeight;
  2386.                     return;
  2387.                 }
  2388.             }
  2389.         }
  2390.     }
  2391.  
  2392.     if ($requestedWidth < 2)
  2393.     {
  2394.         warning "Width must be at least 2 pixels";
  2395.         $requestedWidth = 2;
  2396.     }
  2397.  
  2398.     // We need to test if anything changed to prevent an infinite loop
  2399.     // in the callbacks.
  2400.     if (`getAttr hardwareRenderGlobals.resolutionX` != $requestedWidth)
  2401.         setAttr hardwareRenderGlobals.resolutionX $requestedWidth;
  2402.     optionMenuGrp -edit -sl 1 resolutionMenu;
  2403.     checkMayaHardwareAspectLockWidth;
  2404.  
  2405.     // Update the values
  2406.     updateMayaHardwareResolution;
  2407.  
  2408.     adjustMayaHardwareDeviceAspect;    
  2409.     
  2410.     setParent $oldParent;
  2411. }
  2412.  
  2413. global proc changeMayaHardwareAspectLockHeight()
  2414. //
  2415. //  Procedure Name:
  2416. //      changeAspectLockHeight
  2417. //
  2418. //  Description:
  2419. //        This procedure is called when the user changes the
  2420. //        resolution width.  It sets the internal representation
  2421. //        then looks at the ratio lock etc and changes any other 
  2422. //        values that rely on it. 
  2423. //
  2424. {
  2425.     string $oldParent = `setParent -q`;
  2426.     setParentToCommonTab();
  2427.  
  2428.     int $requestedHeight = `intFieldGrp -q -v1 mayaHardwareResHeight`;
  2429.     int $isMayaEvalVersion = `about -ev`;
  2430.     int $kPLEMaxX = 1024;
  2431.     int $kPLEMaxY =  768;
  2432.     if ($isMayaEvalVersion)
  2433.     {
  2434.         if ($requestedHeight > $kPLEMaxY)
  2435.         {
  2436.             warning("Image resolution is limited to "+$kPLEMaxX+"x"+$kPLEMaxY+" pixels for the Maya Personal Learning Edition");
  2437.             $requestedHeight = $kPLEMaxY;
  2438.         }
  2439.  
  2440.         if (`checkBoxGrp -query -v1 aspectLockCheck`)
  2441.         {
  2442.             global float $deviceAspect;
  2443.             float $aspect = $deviceAspect; 
  2444.  
  2445.             if ($aspect > 0.0)
  2446.             {
  2447.                 int $rez = $requestedHeight / $aspect;
  2448.                 int $oldrez = `getAttr hardwareRenderGlobals.resolutionX`;
  2449.                 if (($rez <= $kPLEMaxX) && ($rez != $oldrez))
  2450.                 {
  2451.                     setAttr hardwareRenderGlobals.resolutionX $rez;
  2452.                 }
  2453.                 else
  2454.                 {
  2455.                     intFieldGrp -e -v1 $kPLEMaxX mayaHardwareResWidth;
  2456.                     changeMayaHardwareAspectLockWidth;
  2457.                     return;
  2458.                 }
  2459.             }
  2460.         }
  2461.     }
  2462.  
  2463.     if ($requestedHeight < 2)
  2464.     {
  2465.         warning "Height must be at least 2 pixels";
  2466.         $requestedHeight = 2;
  2467.     }
  2468.     // We need to test if anything changed to prevent an infinite loop
  2469.     // in the callbacks.
  2470.     if (`getAttr hardwareRenderGlobals.resolutionY` != $requestedHeight)
  2471.         setAttr hardwareRenderGlobals.resolutionY $requestedHeight;
  2472.     optionMenuGrp -edit -sl 1 resolutionMenu;
  2473.     checkMayaHardwareAspectLockHeight;
  2474.  
  2475.     // Update the values
  2476.     updateMayaHardwareResolution;
  2477.  
  2478.     adjustMayaHardwareDeviceAspect;
  2479.     
  2480.     setParent $oldParent;
  2481. }
  2482.  
  2483. global proc adjustMayaHardwareDeviceAspect()
  2484. {
  2485.     string $oldParent = `setParent -q`;
  2486.     setParentToCommonTab();
  2487.  
  2488.     string $nodeName = "hardwareRenderGlobals";
  2489.     string $widthAttr = $nodeName + ".resolutionX";
  2490.     string $heightAttr = $nodeName + ".resolutionY";
  2491.  
  2492.     float $pixelAspectRatio = `getAttr hardwareRenderGlobals.pixelAspectRatio`;
  2493.  
  2494.     float $aspect = (float)`getAttr $widthAttr` / (float)`getAttr $heightAttr`;
  2495.     $aspect = $pixelAspectRatio * $aspect;
  2496.     floatFieldGrp -edit -v1 $aspect resRatio;
  2497.     
  2498.     setParent $oldParent;
  2499. }
  2500.